package io.shuttle.mbe.api

import io.shuttle.mbe.api.annotation.ChromeMinVersion
import io.shuttle.mbe.api.annotation.PromiseStyleMinVersion
import io.shuttle.mbe.api.types.Value1Function
import io.shuttle.mbe.api.types.VoidFunction
import io.shuttle.mbe.core.JSObject
import io.shuttle.mbe.core.Promise
import kotlinx.serialization.SerialName

interface ContentSettings {
    // Whether to allow sites to download multiple files automatically.
    // One of allow: Allow sites to download multiple files automatically,
    // block: Don't allow sites to download multiple files automatically,
    // ask: Ask when a site wants to download files automatically after the first file.
    // Default is ask. The primary URL is the URL of the top-level frame. The secondary URL is not used.
     var automaticDownloads: MultipleAutomaticDownloadsContentSetting

    // Whether to allow sites to use the Private State Tokens API. One of allow:
    // Allow sites to use the Private State Tokens API,
    // block: Block sites from using the Private State Tokens API.
    // Default is allow. When calling set(), the primary URL pattern must be <all_urls>.
    // The secondary URL is not used.
    @ChromeMinVersion(113)
     var autoVerify: AutoVerifyContentSetting

    // Whether to allow sites to access the camera. One of allow:
    // Allow sites to access the camera, block: Don't allow sites to access the camera,
    // ask: Ask when a site wants to access the camera. Default is ask.
    // The primary URL is the URL of the document which requested camera access.
    // The secondary URL is not used. NOTE: The 'allow' setting is not valid if both patterns are '<all_urls>'.
    @ChromeMinVersion(46)
     var camera: CameraContentSetting

    // Whether to allow sites to access the clipboard via advanced capabilities of the Async Clipboard API.
    // "Advanced" capabilities include anything besides writing built-in formats after a user gesture,
    // i.e. the ability to read, the ability to write custom formats,
    // and the ability to write without a user gesture.
    // One of allow: Allow sites to use advanced clipboard capabilities,
    // block: Don't allow sites to use advanced clipboard capabilties,
    // ask: Ask when a site wants to use advanced clipboard capabilities.
    // Default is ask. The primary URL is the URL of the document which requested clipboard access.
    // The secondary URL is not used.
    @ChromeMinVersion(121)
     var clipboard: ClipboardContentSetting

    // Whether to allow cookies and other local data to be set by websites.
    // One of allow: Accept cookies, block: Block cookies, session\_only:
    // Accept cookies only for the current session. Default is allow.
    // The primary URL is the URL representing the cookie origin.
    // The secondary URL is the URL of the top-level frame.
     var cookies: CookiesContentSetting

    // Deprecated. No longer has any effect.
    // Fullscreen permission is now automatically granted for all sites. Value is always allow.
    @Deprecated("Deprecated. No longer has any effect. Fullscreen permission is now automatically granted for all sites. Value is always allow.")
     var fullscreen: FullscreenContentSetting

    // Whether to show images. One of allow: Show images, block:
    // Don't show images. Default is allow.
    // The primary URL is the URL of the top-level frame.
    // The secondary URL is the URL of the image.
     var images: ImagesContentSetting

    // Whether to run JavaScript. One of allow: Run JavaScript, block: Don't run JavaScript.
    // Default is allow. The primary URL is the URL of the top-level frame. The secondary URL is not used.
     var javascript: JavascriptContentSetting

    // Whether to allow Geolocation. One of allow: Allow sites to track your physical location, block:
    // Don't allow sites to track your physical location, ask: Ask before allowing sites to track
    // your physical location.
    // Default is ask. The primary URL is the URL of the document which requested location data.
    // The secondary URL is the URL of the top-level frame (which may or may not differ from the requesting URL).
     var location: LocationContentSetting

    // Whether to allow sites to access the microphone. One of allow: Allow sites to access the microphone,
    // block: Don't allow sites to access the microphone, ask: Ask when a site wants to access the microphone.
    // Default is ask. The primary URL is the URL of the document which requested microphone access.
    // The secondary URL is not used. NOTE: The 'allow' setting is not valid if both patterns are '<all_urls>'.
    @ChromeMinVersion(46)
     var microphone: MicrophoneContentSetting

    // Deprecated. No longer has any effect. Mouse lock permission is now automatically granted for all sites.
    // Value is always allow.
    @Deprecated("Deprecated. No longer has any effect. Mouse lock permission is now automatically granted for all sites. Value is always allow.")
     var mouselock: MouselockContentSetting

    // Whether to allow sites to show desktop notifications. One of allow: Allow sites to show desktop notifications,
    // block: Don't allow sites to show desktop notifications, ask: Ask when a site wants to show desktop notifications.
    // Default is ask. The primary URL is the URL of the document which wants to show the notification.
    // The secondary URL is not used.
     var notifications: NotificationsContentSetting

    // Deprecated. With Flash support removed in Chrome 88, this permission no longer has any effect.
    // Value is always block. Calls to set() and clear() will be ignored.
    @Deprecated("Deprecated. With Flash support removed in Chrome 88, this permission no longer has any effect. Value is always block. Calls to set() and clear() will be ignored.")
     var plugins: PluginsContentSetting

    // Whether to allow sites to show pop-ups. One of allow: Allow sites to show pop-ups, block:
    // Don't allow sites to show pop-ups. Default is block.
    // The primary URL is the URL of the top-level frame. The secondary URL is not used.
     var popups: PopupsContentSetting

    // Deprecated. Previously, controlled whether to allow sites to run plugins unsandboxed,
    // however, with the Flash broker process removed in Chrome 88, this permission no longer has any effect.
    // Value is always block. Calls to set() and clear() will be ignored.
    @Deprecated("Deprecated. Previously, controlled whether to allow sites to run plugins unsandboxed, however, with the Flash broker process removed in Chrome 88, this permission no longer has any effect. Value is always block. Calls to set() and clear() will be ignored.")
     var unsandboxedPlugins: PpapiBrokerContentSetting

   interface ContentSetting {
       // Clear all content setting rules set by this extension.
       @PromiseStyleMinVersion(96)
       fun clear(details: ClearDetails, callback: VoidFunction? = null): Promise<Void>

       // @return The content setting. See the description of the individual ContentSetting objects for the possible values.
       @PromiseStyleMinVersion(96)
       fun get(
           details: GetDetails,
           callback: Value1Function<JSObject>? = null
       ): Promise<JSObject>

       // @return A list of resource identifiers for this content type, or undefined if this content type does not use resource identifiers.
       @PromiseStyleMinVersion(96)
       fun getResourceIdentifiers(callback: Value1Function<List<ResourceIdentifier>>? = null): Promise<List<ResourceIdentifier>>

       @PromiseStyleMinVersion(96)
       fun set(details: SetDetails, callback: VoidFunction? = null): Promise<Void>
   }

    @ChromeMinVersion(113)
    enum class AutoVerifyContentSetting {
        allow,
        block
    }

    @ChromeMinVersion(46)
    enum class CameraContentSetting {
        allow,
        block,
        ask
    }

    @ChromeMinVersion(121)
    enum class ClipboardContentSetting {
        allow,
        block,
        ask
    }

        @ChromeMinVersion(44)
    enum class CookiesContentSetting {
        allow,
        block,

        @SerialName("session_only")
        sessionOnly
    }

    @ChromeMinVersion(44)
    enum class FullscreenContentSetting {
        allow
    }

    @ChromeMinVersion(44)
    enum class ImagesContentSetting {
        allow,
        block
    }

    @ChromeMinVersion(44)
    enum class JavascriptContentSetting {
        allow,
        block
    }

    @ChromeMinVersion(44)
    enum class LocationContentSetting {
        allow,
        block,
        ask
    }

    @ChromeMinVersion(46)
    enum class MicrophoneContentSetting {
        allow,
        block,
        ask
    }

    @ChromeMinVersion(44)
    enum class MouselockContentSetting {
        allow
    }

    @ChromeMinVersion(44)
    enum class MultipleAutomaticDownloadsContentSetting {
        allow,
        block,
        ask
    }

    @ChromeMinVersion(44)
    enum class NotificationsContentSetting {
        allow,
        block,
        ask
    }

    @ChromeMinVersion(44)
    enum class PluginsContentSetting {
        block
    }

    @ChromeMinVersion(44)
    enum class PopupsContentSetting {
        allow,
        block
    }

    @ChromeMinVersion(44)
    enum class PpapiBrokerContentSetting {
        block
    }

    enum class SoundContentSetting {
        allow,
        block
    }

    // The only content type using resource identifiers is contentSettings.plugins.
    // For more information, see Resource Identifiers.
    data class ResourceIdentifier(
        // A human readable description of the resource.
        var description: String?,
        // The resource identifier for the given content type.
        var id: String,
    )

    // The scope of the ContentSetting. One of regular: setting for regular profile (which is
    // inherited by the incognito profile if not overridden elsewhere), incognito\_session\_only:
    // setting for incognito profile that can only be set during an incognito session and is
    // deleted when the incognito session ends (overrides regular settings).
    @ChromeMinVersion(44)
    enum class Scope {
        Regular,
        IncognitoSessionOnly
    }

    data class ClearDetails(
        // Where to clear the setting (default: regular).
        var scope: Scope = Scope.Regular
    )

    data class GetDetails(
        // Whether to check the content settings for an incognito session. (default false)
        var incognito: Boolean?,
        // The primary URL for which the content setting should be retrieved. Note that the meaning of a primary URL depends on the content type.
        var primaryUrl: String,
        // A more specific identifier of the type of content for which the settings should be retrieved.
        var resourceIdentifier: ResourceIdentifier?,
        // The secondary URL for which the content setting should be retrieved. Defaults to the primary URL. Note that the meaning of a secondary URL depends on the content type, and not all content types use secondary URLs.
        var secondaryUrl: String?,
    )

    data class SetDetails(
        // The pattern for the primary URL. For details on the format of a pattern, see Content Setting Patterns.
        var primaryPattern: String,
        // The resource identifier for the content type.
        var resourceIdentifier: ResourceIdentifier?,
        // Where to set the setting (default: regular).
        var scope: Scope = Scope.Regular,
        // The pattern for the secondary URL. Defaults to matching all URLs. For details on the format of a pattern, see Content Setting Patterns.
        var secondaryPattern: String?,
        var setting: Any,
    )
}